#ifndef FHE_CORE_VARDESC_H
#define FHE_CORE_VARDESC_H

#include <fhe/core/IVarDesc.h>
#include <fhe/core/Var.h>

namespace fhe
{
  namespace core
  {
    template <typename T, typename V>
    class VarDesc : public IVarDesc
    {
    public:
      typedef V (T::*P);
      
      VarDesc( P p, const std::string& name )
        : p_( p )
        , name_( name )
      {
      }
      
      IVar::Ptr build( Node* node )
      {
        T* t = dynamic_cast<T*>( node );
        FHE_ASSERT_MSG( t != 0, "unable to cast node to %s", typeid(T).name() );
        return IVar::Ptr( new Var<T,V>( t, p_, name_ ) );
      }
      
      std::string name() const
      {
        return name_;
      }
      
    private:
      P p_;
      std::string name_;
    };
  }
}

#endif
